<?php
/**
 * Created by : Sandi Rizky Kharisma (sandi.informatics08@gmail.com)
 * This Class Generated for CRUD purpose only
 */
class m_barang_toko extends CI_Model
{

    function __construct()
    {
        parent::__construct();
    }

    public function get($where = null, $limit = null, $offset = null)
    {
        if($where != null) $this->db->where($where);
        if($limit != null && $offset != null) $this->db->limit($limit, $offset);
        return $this->db->get("barang_toko");
    }

    function get_all($limit, $uri)
    {

        $result = $this->db->get('barang_toko', $limit, $uri);
        if ($result->num_rows() > 0)
        {
            return $result->result_array();
        } else
        {
            return array();
        }
    }

    function get_one($id)
    {
        $this->db->where('', $id);
        $this->db->delete('barang_toko');
    }

    function insert($id_toko = null, $kode_barang = null)
    {
        $name_table = ($id_toko == null) ? 'barang_toko' : "barang_toko_$id_toko";

        $data = array(

                'KODE_BARANG' => $kode_barang,

                'HARGA_BELI' => $this->input->post('HARGA_BELI', TRUE),

                'HARGA_JUAL' => $this->input->post('HARGA_JUAL', TRUE),

                'JUMLAH_AWAL' => $this->input->post('JUMLAH_AWAL', TRUE),

                'STOK_MIN' => $this->input->post('STOK_MIN', TRUE),

                'JUMLAH_AKHIR' => $this->input->post('JUMLAH_AKHIR', TRUE),

                'DISKON' => $this->input->post('DISKON', TRUE),

                'TGL_ENTRY' => date("Y-m-d H:i:s")

        );
        return $this->db->insert($name_table, $data);
    }

    function insert($id_toko = null, $kode_barang = null)
    {
        $name_table = ($id_toko == null) ? 'barang_toko' : "barang_toko_$id_toko";

        $data = array(
                'HARGA_BELI' => $this->input->post('HARGA_BELI', TRUE),

                'HARGA_JUAL' => $this->input->post('HARGA_JUAL', TRUE),

                'JUMLAH_AWAL' => $this->input->post('JUMLAH_AWAL', TRUE),

                'STOK_MIN' => $this->input->post('STOK_MIN', TRUE),

                'JUMLAH_AKHIR' => $this->input->post('JUMLAH_AKHIR', TRUE),

                'DISKON' => $this->input->post('DISKON', TRUE),

                'TGL_ENTRY' => date("Y-m-d H:i:s")

        );
        $this->db->where('KODE_BARANG', $kode_barang);
        return $this->db->update($name_table, $data);
    }

}
?>
